public class ListNode {
    int val;
    ListNode next;

    ListNode(int val) {
        this.val = val;
    }

    @Override
    public String toString() {
        if (next == null)
            return val + "";
        return val + "->" + next.toString();
    }
}
